package java44th.group.controller.wx.feedback;

import java44th.group.bean.admin.vo.BaseRespVo;
import java44th.group.bean.po.MarketUser;
import java44th.group.bean.wx.vo.feedback.WxFeedbackSubmitBo;
import java44th.group.service.wx.feedback.WxFeedbackService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 小焦
 * @since 2022/10/15 17:38
 */

@RestController
@RequestMapping("wx/feedback")
public class WxFeedbackController {
    @Autowired
    WxFeedbackService feedbackService;
    /**
     * 获取参数 : {mobile: "1234567890", feedType: "商品相关", content: "qunide", hasPicture: false, picUrls: []}
     * 返回响应 :
     *
     * @return java44th.group.bean.admin.vo.BaseRespVo
     * @author 小焦
     * @since 2022/10/15 下午 05:40
     */
    @PostMapping("submit")
    public BaseRespVo submit(@RequestBody WxFeedbackSubmitBo submitBo) {
        Subject subject = SecurityUtils.getSubject();
        MarketUser primaryPrincipal = (MarketUser) subject.getPrincipals().getPrimaryPrincipal();
        Integer userId = primaryPrincipal.getId();
        String username = primaryPrincipal.getUsername();
        int code=feedbackService.submit(submitBo,userId,username);
        if(code==1){
            return BaseRespVo.ok();
        }
        return BaseRespVo.invalidParameter("反馈失败");
    }

}
